package org.jeecg.modules.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.jeecg.modules.order.entity.WlhyOrder;
import org.jeecg.modules.order.mapper.WlhyOrderMapper;
import org.jeecg.modules.order.service.IWlhyOrderService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.time.LocalDateTime;
import java.util.List;

import static org.jeecg.common.constant.WlhyBizConstant.*;

/**
 * @Description: 订单表
 * @Author: jeecg-boot
 * @Date:   2024-04-18
 * @Version: V1.0
 */
@Service
public class WlhyOrderServiceImpl extends ServiceImpl<WlhyOrderMapper, WlhyOrder> implements IWlhyOrderService {

    @Override
    public WlhyOrder getByOrderNo(String orderNo) {
        return getOne(new LambdaQueryWrapper<WlhyOrder>().eq(WlhyOrder::getOrderNo,orderNo));
    }

    @Override
    public void expireJobHandler() {
        // 查询 支付中 过期时间大于当前时间 的订单
        List<WlhyOrder> list = list(new LambdaQueryWrapper<WlhyOrder>()
                .eq(WlhyOrder::getOrderState, ORDER_STATE1)
                .le(WlhyOrder::getExpiredTime, LocalDateTime.now())
        );
        for (WlhyOrder wlhyOrder : list) {
            update(new LambdaUpdateWrapper<WlhyOrder>()
                    .eq(WlhyOrder::getId, wlhyOrder.getId())
                    .set(WlhyOrder::getOrderState, ORDER_STATE6)
            );
        }
    }
}
